package com.bobby.shop.service.impl;

import com.bobby.shop.mapper.UserMapper;
import com.bobby.shop.pojo.User;
import com.bobby.shop.pojo.UserExample;
import com.bobby.shop.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description TODO
 * @Date 2020/12/10 15:33
 * @Created wenjunpei
 */
@Transactional
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByLoginName(String loginName) {
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        criteria.andLoginNameEqualTo(loginName);
        List<User> users = userMapper.selectByExample(userExample);
        if(users.size() == 0) {
            return null;
        }else {
            return users.get(0);
        }
    }

    @Override
    public void saveUser(User user) {
       userMapper.insert(user);
    }
}
